package org.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.example.entity.CouponType;
import org.example.entity.SysCoupon;
import org.example.entity.SysDictionary;
import org.example.service.ICouponTypeService;
import org.example.service.ISysCouponService;
import org.example.service.ISysDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhaowenting
 * @since 2024-04-14
 */
@RestController
@RequestMapping("/sys-coupon")
public class SysCouponController {
    @Autowired
    ICouponTypeService iCouponTypeService;
    @Autowired
    ISysCouponService iSysCouponService;
    @Autowired
    ISysDictionaryService iSysDictionaryService;
    /**
     * 查询优惠券类型列表
     * @return
     */
    @RequestMapping("couponTypeList")
    public List<CouponType> couponTypeList(){
        final List<CouponType> list = iCouponTypeService.list();
        return list;
    }
    /**
     * 查询优惠券适用范围
     * @return
     */
     @RequestMapping("couponScopeList")
     public List<SysDictionary> couponScopeList(){
         final LambdaQueryWrapper<SysDictionary> sysDictionaryLambdaQueryWrapper = new LambdaQueryWrapper<>();
         sysDictionaryLambdaQueryWrapper.eq(SysDictionary::getSysType,"scrop_coupon_state");
         final List<SysDictionary> list = iSysDictionaryService.list(sysDictionaryLambdaQueryWrapper);
         return list;
     }

    /**
     * 添加优惠券方法
     * @param sysCoupon
     * @return
     */
     @RequestMapping("addGoodsCoupon")
    public String addGoodsCoupon(@RequestBody SysCoupon sysCoupon){
         System.out.println("前端传过来的优惠券信息：==="+sysCoupon);
         iSysCouponService.save(sysCoupon);
         return "success";
     }
}
